import { request } from '@umijs/max';
import * as API from "@/services";

export async function queryUsers(params: API.UserPageQueryParams): Promise<API.RespPageResult<API.User>> {
    return request('/api/v1/user', {
        params,
    });
}
export async function queryUser(bizId: API.EntityId): Promise<API.RespResult<API.User>> {
    return request(`/api/v1/user/${bizId}`);
}

/**
 * 获取当前登录用户信息
 * @param opts
 */
export async function queryCurrentUser(opts?: API.AxiosRequestOpts) {
    return request<API.RespResult<API.User>>('/api/v1/current-user', {
        ...(opts || {}),
    });
}

export async function modifyCurrentUser(entity: API.User_Modify): Promise<API.RespResult<any>> {
  return request(`/api/v1/user/current`, {
    method: 'PUT',
    data: entity,
  });
}


export async function createUser(entity: API.User_Create): Promise<API.RespResult<any>> {
    return request(`/api/v1/user`, {
        method: 'POST',
        data: entity,
    });
}

export async function modifyUser(entity: API.User_FullModify): Promise<API.RespResult<any>> {
    return request(`/api/v1/user/${entity.id}`, {
        method: 'PUT',
        data: entity,
    });
}

export async function patchUser(entity: API.User_FullPatch): Promise<API.RespResult<any>> {
    return request(`/api/v1/user/${entity.id}`, {
        method: 'PATCH',
        data: entity,
    });
}

export async function deleteUser(bizId: API.EntityId): Promise<API.RespResult<any>> {
    return request(`/api/v1/user/${bizId}`, {
        method: 'DELETE',
    });
}

export async function deleteUsers(bizIds: API.EntityId[]): Promise<API.RespResult<any>> {
    return request(`/api/v1/user`, {
        method: 'DELETE',
        data: {
            ids: bizIds,
        },
    });
}

export async function enableUser(bizId: API.EntityId): Promise<API.RespResult<any>> {
    return request(`/api/v1/user/${bizId}/enable`, {
        method: 'PUT',
    });
}

export async function disableUser(bizId: API.EntityId): Promise<API.RespResult<any>> {
    return request(`/api/v1/user/${bizId}/disable`, {
        method: 'PUT',
    });
}
